{% extends "common/layout.html" %}
{% block content %}
    {#标题#}
    <div class="row">
        <div class="col-sm-12 ">
            <div class="row">
                <div class="col-sm-10 ">
                    <h2>承建商入库审查前存档</h2>
                </div>
            </div>
        </div>
    </div>


    <div class="row" style="margin-top: 30px">
        <div class="col-sm-12 ">

            {#搜索#}

            <div class="row search">

                <div class="col-sm-1 ">
                    <label>所属公司</label>
                    <select class="selectpicker form-control" ata-live-search="true"
                            title="请选择" data-hide-disabled="true" multiple name="area">
                        <option>不限</option>
                        <option>山西公司</option>
                        <option>陕西公司</option>
                        <option>内蒙古公司</option>
                        <option>乌鲁木齐公司</option>
                        <option>兰州公司</option>
                    </select>
                </div>

                <div class="col-sm-1 ">
                    <label>工程类别</label>
                    <select class="selectpicker form-control" name="gctype" ata-live-search="true"
                            title="请选择" data-hide-disabled="true" multiple>
                        <optgroup label="A">
                            {% for item in parterclassa %}
                                <option>{{ item.name }}</option>
                            {% endfor %}
                        </optgroup>
                        <optgroup label="B">
                            {% for item in parterclassb %}
                                <option>{{ item.name }}</option>
                            {% endfor %}
                        </optgroup>
                    </select>
                </div>


                <div class="col-sm-1 ">
                    <label>专业类别</label>
                    <select class="selectpicker form-control" name="zytype"
                            title="请选择" data-hide-disabled="true" multiple>
                        <option>A</option>
                        <option>B</option>
                    </select>
                </div>


                <div class="col-sm-1 ">
                    <label>是否完成</label>
                    <select class="form-control " name="isdone">
                        <option>不限</option>
                        <option>是</option>
                        <option>否</option>
                    </select>
                </div>


                <div class="col-sm-1 ">
                    <label>日期类型</label>
                    <select class="form-control " name="datetype">
                        <option>预审日期</option>
                        <option>考察日期</option>
                    </select>
                </div>


                <div class="col-sm-4">
                    <label>日期</label>
                    <div class="input-group">
                        <span class="input-group-addon">开始日期</span>
                        <a class='input-group date' id='datetimepicker1'>
                            <input type='text' class="form-control" id="sdate" name="sdate"/>
                            <span class="input-group-addon">
		                    <span class="glyphicon glyphicon-calendar"></span>
		                </span>
                        </a>
                        <span class="input-group-btn">-</span>
                        <span class="input-group-addon">结束日期</span>
                        <a class='input-group date' id='datetimepicker2'>
                            <input type='text' class="form-control" id="edate" name="edate"/>
                            <span class="input-group-addon">
		                    <span class="glyphicon glyphicon-calendar"></span>
		                </span>
                        </a>

                    </div>
                </div>

                <script type="text/javascript">

                    $('#datetimepicker1').datetimepicker({
                        format: 'YYYY-MM-DD',
                        locale: moment.locale('zh-cn')
                    });

                    $('#datetimepicker2').datetimepicker({
                        format: 'YYYY-MM-DD',
                        locale: moment.locale('zh-cn')
                    });

                </script>

                <div class="col-sm-2 ">
                    <label>公司名称</label>
                    <input class="form-control " name="name">
                </div>


                <div class='col-sm-1'>
                    <div class="form-group">
                        <label></label>
                        <button type="submit" class="btn btn-primary btn-block do-search " id="dosearch">
                            搜索
                        </button>

                    </div>


                    <script type="text/javascript">
                        {#搜索#}
                        var dosearch = {
                            init: function () {
                                this.eventBind()
                            },
                            eventBind: function () {
                                $(".do-search").click(function () {
                                    var gctype = $(".search select[name=gctype]").val();
                                    var zytype = $(".search select[name=zytype]").val();
                                    var name = $(".search input[name=name]").val();
                                    var sdate = $(".search input[name=sdate]").val();
                                    var edate = $(".search input[name=edate]").val();
                                    var isdone = $(".search select[name=isdone]").val();
                                    var area = $(".search select[name=area]").val();
                                    var datetype = $(".search select[name=datetype]").val();
                                    var urlindex = common_ops.buildUrl("/parter/partersearch?gctype=") + gctype + "&zytype=" + zytype + "&name=" + name + "&mark=1" + "&sdate=" + sdate + "&edate=" + edate + "&isdone=" + isdone + "&datetype=" + datetype + "&area=" + area;
                                    document.location.href = urlindex;

                                });
                            }
                        };
                        $(document).ready(function () {
                            dosearch.init();
                        });
                    </script>
                </div>
            </div>


            {#        新建#}

            <div class="row">


                <button type="button" class="btn btn-info" data-toggle="modal"
                        data-target="#exampleModal" style="margin-top: 10px;margin-left: 15px" data-type=""
                        data-name="" data-address=""
                        data-owner="" data-phone=""
                        data-gctype="" data-zytype=""
                        data-id="" data-linker=""
                        data-title="" data-offer=""><span
                        class="glyphicon glyphicon-plus" aria-hidden="true"></span>新建承建商
                </button>


            </div>

            {#表格#}
            <row class=" data-table">

                <table class="table table-bordered table-hover">
                    <tr>
                        <th class="info">所属公司</th>
                        <th class="info">名称</th>
                        <th class="info">性质</th>

                        <th class="info">地址</th>
                        <th class="info">法人</th>
                        <th class="info">联系人</th>
                        <th class="info">联系方式</th>
                        <th class="info">工程类别</th>
                        <th class="info">专业类别</th>
                        <th class="info">状态</th>
                        <th class="info">推荐人/部门</th>
                        <th class="info">操作</th>

                    </tr>
                    {% for item in parterindex %}

                        <tr>
                            <th>{{ item.area }}</th>
                            <th>{{ item.name }}</th>
                            <th>{{ item.type }}</th>

                            <th>{{ item.address }}</th>
                            <th>{{ item.owner }}</th>
                            <th>{{ item.linker }}</th>
                            <th>{{ item.phone }}</th>
                            <th>{{ item.gctype }}</th>
                            <th>{{ item.zytype }}</th>
                            <th>{{ item.status }}</th>
                            <th>{{ item.offer }}</th>


                            <th><a class="btn btn-success"
                                   href="{{ buildUrl('/parter/parterdetail') }}?id={{ item.id }}">查看</a>

                                {#                                {% if item.company ==  current_user.company or current_user.company== "西北区域公司" %}#}

                                <button type="button" class="btn btn-primary" data-toggle="modal"
                                        data-target="#exampleModal" data-type="{{ item.type }}"
                                        data-name="{{ item.name }}" data-address="{{ item.address }}"
                                        data-owner="{{ item.owner }}" data-phone="{{ item.phone }}"
                                        data-gctype="{{ item.gctype }}" data-zytype="{{ item.zytype }}"
                                        data-id="{{ item.id }}" data-linker="{{ item.linker }}"
                                        data-offer="{{ item.offer }}" data-area="{{ item.area }}"
                                        data-title="编辑">编辑
                                </button>

                                <button type="button" class="btn btn-danger" data-toggle="modal"
                                        data-target="#conModal" data-id="{{ item.id }}">删除
                                </button>

                                {#                                {% endif %}#}

                            </th>
                        </tr>

                    {% endfor %}
                </table>
            </row>

            {#        分页#}
            {% if pages %}
                <div>
                    <p style="margin-left: 5px">共{{ num }}条数据</p>
                    {% include "common/pagenation.html" %}
                </div>
            {% endif %}
        </div>
    </div>


    {#    确认模态框#}
    <div class="modal fade" id="conModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">操作确认</h4>
                </div>
                <div class="modal-body">
                    <p>是否确定删除?</p>
                    <input type="text" style="display:none" id="deleteid" name="deleteid">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button class="btn btn-danger do-delete" type="submit" name="delete" id="delete">确定删除</button>
                </div>
            </div>
        </div>
    </div>


    {#    模态框#}
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel">新建承建商</h4>
                </div>
                <div class="modal-body">
                    <input type="text" class="invisible" id="uid" name="uid" value="{{ current_user.id }}">
                    <input type="text" class="invisible" id="id" name="id">


                    <div class="form-group">
                        <label for="recipient-name" class="control-label">所属公司:</label>
                        <select class="form-control " id="area" name="area">
                            <option>请选择</option>
                            <option>山西公司</option>
                            <option>陕西公司</option>
                            <option>内蒙古公司</option>
                            <option>乌鲁木齐公司</option>
                            <option>兰州公司</option>
                        </select>
                    </div>


                    <div class="form-group">
                        <label class="control-label">公司名称:</label>
                        <input type="text" class="form-control" id="name" name="name">
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">公司性质:</label>
                        <input type="text" class="form-control" id="type" name="type">
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">公司地址:</label>
                        <input type="text" class="form-control" id="address" name="address">
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">公司法人:</label>
                        <input type="text" class="form-control" id="owner" name="owner">
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">公司联系人:</label>
                        <input type="text" class="form-control" id="linker" name="linker">
                    </div>

                    <div class="form-group">
                        <label for="recipient-name" class="control-label">联系方式:</label>
                        <input type="number" class="form-control" id="phone" name="phone">
                    </div>


                    <div class="form-group">
                        <label for="recipient-name" class="control-label">专业类型:</label>
                        <select class="selectpicker form-control " id="zytype" name="zytype" multiple>
                            <option>A</option>
                            <option>B</option>
                        </select>
                    </div>


                    <div class="cform-group">
                        <label for="recipient-name" class="control-label">工程类型:</label>
                        <select class="selectpicker form-control" id="gctype" name="gctype" data-live-search="true"
                                title="请选择" data-hide-disabled="true"
                                multiple>
                            <optgroup label="A">
                                {% for item in parterclassa %}
                                    <option>{{ item.name }}</option>
                                {% endfor %}
                            </optgroup>
                            <optgroup label="B">
                                {% for item in parterclassb %}
                                    <option>{{ item.name }}</option>
                                {% endfor %}
                            </optgroup>
                        </select>
                    </div>


                    <div class="form-group">
                        <label for="recipient-name" class="control-label">推荐人/部门:</label>
                        <input type="text" class="form-control" id="offer" name="offer">
                    </div>


                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button class="btn btn-primary do-add" type="submit" name="add" id="add">新建存档</button>
                        <button class="btn btn-primary do-updata" type="submit" name="updata" id="updata">更新存档</button>
                    </div>

                </div>

            </div>
        </div>
    </div>

    {#    更新文档#}
    <script>
        $(".do-updata").click(function () {
            var btnaction = $(this);
            if (btnaction.hasClass("disable")) {
                common_ops.alert("还没提交上去了，别瞎点")
                return
            }

            var name = $("input[id=name]").val();
            var address = $("input[id=address]").val();
            var phone = $("input[id=phone]").val();
            var linker = $("input[id=linker]").val();
            var owner = $("input[id=owner]").val();
            var type = $("input[id=type]").val();
            var gctype = $("select[id=gctype]").val().toString();
            var zytype = $("select[id=zytype]").val().toString();
            var uid = $("input[id=uid]").val();
            var id = $("input[id=id]").val();
            var offer = $("input[id=offer]").val();
            var area = $("select[id=area]").val();


            $.ajax({
                url: common_ops.buildUrl("/parter/updataindex"),
                type: "POST",
                data: {
                    name: name,
                    address: address,
                    owner: owner,
                    linker: linker,
                    type: type,
                    gctype: gctype,
                    zytype: zytype,
                    phone: phone,
                    uid: uid,
                    id: id,
                    offer: offer,
                    area: area,
                },
                dataType: 'json',
                success: function (res) {
                    btnaction.removeClass("disabled");
                    var callback = null;
                    if (res.code == 200) {
                        callback = function () {
                        };
                    }
                    common_ops.alert(res.msg, callback);
                    setTimeout(function () {
                        $('#exampleModal').modal('hide');
                        $(".modal-backdrop.fade").hide();
                        window.location.href = common_ops.buildUrl("/parter/parterindex");
                        $("#exampleModal").trigger("click");
                    }, 1000)
                }
            });

        });
    </script>


    <script>
        $(".do-add").click(function () {
            var btnaction = $(this);
            if (btnaction.hasClass("disable")) {
                common_ops.alert("还没提交上去了，别瞎点")
                return
            }

            var name = $("input[id=name]").val();
            var address = $("input[id=address]").val();
            var phone = $("input[id=phone]").val();
            var linker = $("input[id=linker]").val();
            var owner = $("input[id=owner]").val();
            var type = $("input[id=type]").val();
            var gctype = $("select[id=gctype]").val().toString();
            var zytype = $("select[id=zytype]").val().toString();
            var uid = $("input[id=uid]").val();
            var offer = $("input[id=offer]").val();
            var area = $("select[id=area]").val();


            $.ajax({
                url: common_ops.buildUrl("/parter/addindex"),
                type: "POST",
                data: {
                    name: name,
                    address: address,
                    owner: owner,
                    linker: linker,
                    type: type,
                    gctype: gctype,
                    zytype: zytype,
                    phone: phone,
                    uid: uid,
                    offer: offer,
                    area: area,
                },
                dataType: 'json',
                success: function (res) {
                    btnaction.removeClass("disabled");
                    var callback = null;
                    if (res.code == 200) {
                        callback = function () {
                        };
                    }
                    common_ops.alert(res.msg, callback);
                    setTimeout(function () {
                        $('#exampleModal').modal('hide');
                        $(".modal-backdrop.fade").hide();
                        window.location.href = common_ops.buildUrl("/parter/parterindex");
                        $("#exampleModal").trigger("click");
                    }, 1000)


                }
            });

        });
    </script>


    {#删除数据#}
    <script>
        $(".do-delete").click(function () {
            var btnaction = $(this);
            if (btnaction.hasClass("disable")) {
                common_ops.alert("还没提交上去了，别瞎点")
                return
            }

            var deleteid = $("input[id=deleteid]").val();
            console.log(deleteid);


            $.ajax({
                url: common_ops.buildUrl("/parter/deleteindex"),
                type: "GET",
                data: {
                    id: deleteid,
                },
                dataType: 'json',
                success: function (res) {
                    btnaction.removeClass("disabled");
                    var callback = null;
                    if (res.code == 200) {
                        callback = function () {
                        };
                    }
                    common_ops.alert(res.msg, callback);
                    setTimeout(function () {
                        $('#conModal').modal('hide');
                        $(".modal-backdrop.fade").hide();
                        window.location.href = common_ops.buildUrl("/parter/parterindex");
                        $("#exampleModal").trigger("click");
                    }, 1000)

                }
            });

        });
    </script>


    <script>
        {#编辑赋值#}
        $('#exampleModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget); // Button that triggered the modal
            var id = button.data('id');
            var title = button.data('title');
            var gctype = button.data('gctype').split(",")
            var zytype = button.data('zytype').split(",")

            var modal = $(this)
            modal.find('.modal-title').text(title + '承建商');

            $("input[id=id]").val(id);
            $("input[id=name]").val(button.data('name'));
            $("input[id=address]").val(button.data('address'));
            $("input[id=owner]").val(button.data('owner'));
            $("input[id=linker]").val(button.data('linker'));
            $("input[id=phone]").val(button.data('phone'));
            $("input[id=type]").val(button.data('type'));
            $("input[id=offer]").val(button.data('offer'));
            $("select[id=zytype]").val(button.data('zytype'));
            $("select[name=area]").val(button.data('area'));
            $("select[name=gctype]").selectpicker('val', gctype);
            $("select[name=zytype]").selectpicker('val', zytype);


            if (typeof (id.length) == 'undefined') {
                document.getElementById("add").style.display = "none";
                document.getElementById("updata").style.display = "";

            } else {
                document.getElementById("updata").style.display = "none";
                document.getElementById("add").style.display = "";
            }


        });


        {#删除赋值#}
        $('#conModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var deleteid = button.data('id');
            document.getElementById("deleteid").value = deleteid;
        });
    </script>





{% endblock %}


{% block js %}

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="{{ buildStaticUrl('/plugins/bootstrap-select/bootstrap-select.css') }}">

    <script src="{{ buildStaticUrl('/js/jquery1.11.3.js') }}"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="{{ buildStaticUrl('/plugins/bootstrap-select/bootstrap-select.js') }}"></script>

{% endblock %}


